package com.smartdot.bluetoothidcarddemo.camera;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;

import java.util.ArrayList;

public class FaceView extends View {
    private Paint mPaint;
    private ArrayList<RectF> mFaces;
    private Context mContext;
    public FaceView(Context context) {
        super(context);
        this.mContext = context;
        init();
    }

    public FaceView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
        init();
    }

    public FaceView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mContext = context;
        init();
    }
    private void init() {
        mPaint = new Paint();
        mPaint.setColor(Color.WHITE);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1f, mContext.getResources().getDisplayMetrics()));
        mPaint.setAntiAlias(true);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if(mFaces!=null){
            for (RectF mFace : mFaces) {
                canvas.drawRect(mFace, mPaint);
            }
        }
    }

     public void setFaces(ArrayList<RectF> faces) {
        this.mFaces = faces;
        invalidate();
    }

     public void clearFaces() {
        this.mFaces = new ArrayList<>();
        invalidate();
    }
}
